package com.xxxx.parfun

/**
 * @program: day0303
 * @description: 尽信书，则不如无书
 * @author: CoreDao
 * @create: 2021-03-03 17:28
 * */
//基本不会主动使用，但要能看懂
//只有match，没有case
//通过list中map和collect来体现偏函数区别
/**
 * isDefinedAt定义接收参数的范围
 * apply 具体应用
 * 偏函数只处理自己感兴趣的数据
 *
 */
object ParFunTest {

  def MyTest:PartialFunction[Any,Int] = {
    case i: Int => i + 1

  }

  def main(args: Array[String]): Unit = {
    val list = List(1, 3, 5, "seven")
    //用map会报错，seven不匹配
//    list.map(MyTest).foreach(println)

    list.collect(MyTest).foreach(println)



    //逻辑简单例子
    println(MyTest1("hello"))
    def MyTest1:PartialFunction[String,String]={
      case "hello" => "hello"
      case "hello1" => "hello1"
      case "hello2" => "hello2"
      case _ => "no match"

    }
  }
}
